beginoutdoorscript;

variables;
short choice = 0;
short pc_cycle = 0;

body;

beginstate 0; //INIT_STATE

break;

beginstate 1; //EXIT_STATE

break;

beginstate 2; //START_STATE

break;

beginstate 4; //Guards
	outdoor_enc_result(1);
	if(get_flag(201, 14) != 1) {
		reset_dialog();
		add_dialog_str(0, "Walking by the road, you run into a group of patrolling guards. Once they see that you're not lizards, they approach you." , 0);
		add_dialog_str(1, "_You might want to watch yourselves out here._ a guard tells you. _There are more lizards out here than we've ever seen before, and we can't protect everyone._", 0);
		add_dialog_str(2, "You quietly assure them that you can handle a few lizards, and they depart uneasily. From the look of them, you're not sure that those guards could handle a drake between them. Hopefully, you can help them before things in the valley get really bad.", 0);
		run_dialog(1);
	 	set_flag(201,14,1);
		}
	else {
		print_str("You greet the guards on the road.");
		}
break;

beginstate 7; //general farmhouse
	block_entry(1);
	message_dialog("This appears to be a normal farmhouse, with a few livestock wandering about. However, you can tell that the farmers are slightly on edge, particularly given how many are carrying swords.","These people don't look like they want to talk with you... the lizards appear to have put them on edge.");
	break;

//STATES 10-19: Order Preserve

beginstate 10;
//Set up encounter to rescue Oakleaf
	reset_dialog();
	add_dialog_str(0, "In this small camp by the preserve's lake, you immediately notice that something is amiss. Four sets of scorch marks lead from the camp's fire towards a drake and three fire lizards, who are currently threatening a druid.", 0);
	add_dialog_str(2,"The druid appears to be beckoning to you for help. Naturally, you rush in at the drake, hoping to rescue the unfortunate druid.", 0);
	add_dialog_choice(0, "Charge!");
	run_dialog(1);
	set_out_fight_town_loaded(7);

break;

beginstate 11;
//Entering Inner Order Preserve
	//If you've rescued Oakleaf already
	if ((get_flag(201,0) != 1) && (get_flag(201,1) == 1)) { 
		reset_dialog();
		message_dialog("Having saved Brother Oakleaf, you enter the inner section of the Order's preserve, and are stunned by the sheer scale of the surrounding forest. You should probably head for the Temple to see what exactly is going on.","");
		set_flag(201,0,1);
	}
	//If you haven't rescued Oakleaf yet
	if ((get_flag(201,0) != 1) && (get_flag(201,1) != 1)) { 			block_entry(1);
		reset_dialog();
		message_dialog("You enter the inner section of the Order's preserve, and suddenly remember that you still need to find Brother Oakleaf. Maybe you should search the rest of the preserve first, so you can find out what's going on.","");
	}
	//If you've already entered the inner preserve
	if (get_flag(201,0) == 1)
		end();
break;

beginstate 12;
//Talk with Oakleaf - after successful encounter
	set_flag(201,1,1);
	reset_dialog();
	add_dialog_str(0, "Having killed the drake and its allies, the druid you saved introduces himself as Brother Oakleaf, a member of the Order.", 0);
	add_dialog_str(1, "_Before you ask, I am the one who left the note in your cell. I would've helped you escape the cells personally, but I was busy searching for Brother Ephesos around the Temple._",0); 
	add_dialog_str(2, "_As to your imprisonment, the foul members of the Order of Flame who broke into the Temple threw you in our disused cells._", 0);
	add_dialog_str(3, "_Anyway, something horrible has befallen the Order, as you already know. I have the responsibility to find Ephesos, and now that you've helped me finish off those foul lizards, I can continue my quest._", 0);
	add_dialog_str(4, "_Right now, I need to go to Relias to get some equipment. I'll be there for some time, so meet me there if you wish to help in my quest. Until we meet again, adventurers..._", 0);
	add_dialog_str(5, "You seriously doubt that one person can take on the Order of Flame, particularly if he can't beat a few lizards by himself. But, he does seem to know what's going on, unlike you.", 0);
	run_dialog(1);
	award_party_xp(500, 25);
	toggle_quest(0,0);
	toggle_quest(1,1);
break;

beginstate 15;
//Keep party from exiting Preserve until Oakleaf is saved and temple is visited
//Give party direction after visiting temple
	if (get_flag(201,1) != 1) {
	//Can't leave 'till you find Oakleaf
		block_entry(1);
		reset_dialog();
		message_dialog("Hold on a second! You still need to find Brother Oakleaf, so he can tell you what's going on!","");
		}
	else {
		if (get_flag(3,1) != 1) {
		//Herd party into Temple
			block_entry(1);
			reset_dialog();
			message_dialog("Hm... perhaps it would be a good idea to head to the Temple before you leave the Order's preserve. Maybe someone there can give you a good idea of what on earth is going on...","");
			}
	if ((get_flag(201,3) == 1) && (get_flag(201,6) != 1)) {
		//Notice drakes for Orrin quest
		message_dialog("As you enter the Order Preserve again, you see a pair of drakes gliding through the air to the far south. Both of them descend by what appears to be a stone circle, though it's hard to tell from here.","");
		set_flag(201,6,1);
		}
	}
	if ((get_flag(3,1) == 1) && (get_flag(201,12) != 1)) { //After Pinebranch's speech
		//Give party some direction
		reset_dialog();
		message_dialog("Now that you've learned a bit more about what's going on, it's time to find Brother Oakleaf and help find Ephesos. The last hint he gave was that he'd be getting equipment at Relias.","Relias is supposed to be to the north somewhere, so maybe you should head that way.");
		set_flag(201,12,1);
	}	
	
break;

beginstate 16;
//Impending encounter to save Oakleaf
	if (get_flag(201,2) != 1) {
		reset_dialog();
		message_dialog("To the south, you think you see a small drake descend by the water's edge. It might be a good idea to approach carefully.","");
		set_flag(201,2,1);
		}
break;

//STATES 20-29: Orrin

beginstate 20;
//Orrin
	block_entry(1);
//Orrin drake-killing quest
	if((get_flag(201,3) == 1) && (get_flag(201,4) != 1)) {
		//If you've got the quest, but no dead drakes
		reset_dialog();
		message_dialog("You greet the citizens of Orrin, reporting that you haven't found any drakes yet. The people insist that you search again.","");
		}
	if(get_flag(201,3) != 1) {
		//If you don't have the quest
		reset_dialog();
		add_dialog_str(0, "As you reach the edges of Orrin, a crowd of townsfolk rushes out at you, screaming something about a drake.", 0);
		add_dialog_str(1, "A young woman approaches you. _Adventurers, we have seen a terrible omen! Two drakes just flew over the town, and they were headed toward the Order's Preserve!_", 0);
		add_dialog_str(2, "Well, that's just great. It'd probably be wise to check on that.",0);
		run_dialog(1);
		set_flag(201,3,1);
		toggle_quest(2,1);
		}
	if((get_flag(201,4) == 1) && (get_flag(201,7) != 1)) {
		//Killed drakes, but haven't been rewarded yet
		reset_dialog();
		add_dialog_str(0, "As you reach the edge of town, you tell a nervous-looking group of farmers to stop worrying because you've slain the drakes. Almost instantly, a crowd rushes from the town to surround you and congratulate you.", 0);
		add_dialog_str(1, "The mayor of Orrin approaches you, shaking your hand endlessly and babbling about civic duty. You begin to listen attently, however, once he mentions your reward.", 0);
		add_dialog_str(2, "_In honor of your achievement, I present you with this ring, which has been in my family for generations. Please also accept some payment in coin._ Naturally, you accept.", 0);
		run_dialog(1);
		change_coins(1000);
		award_party_xp(500,25);
		char_give_item(0,273);
		set_flag(201,7,1);
		inc_flag(100,2,1); //Chalk up a quest point for Oakleaf
		toggle_quest(2,0);
		}	
//Orrin Bazaar
	if((get_flag(201,7) == 1) && (get_flag(201,7) == 1)) { 
		reset_dialog();
		if (get_flag(201,5) != 1) {
			add_dialog_str(0, "You enter the small city of Orrin, and note the general prosperity of the town. Sadly, the inhabitants all seem a bit depressed, apparently from the news of Ephesos's abduction.", 0);
			add_dialog_str(1, "Walking through the town bazaar, you can't help but feel a little bad for these people. However, the equipment they're selling still looks good.",0);
			set_flag(201,5,1);
			}
		else {
			add_dialog_str(0, "You return to the Orrin bazaar, greeting the merchants cheerfully. The merchants reply in kind, and you can tell they're hoping you'll buy something.", 0);
			}
		add_dialog_choice(0, "Leave");
		add_dialog_choice(1, "Shop");
		choice = run_dialog(1);
		if (choice == 2) {
			add_item_to_shop(7,12,500); //Add sandwich shop to bazaar
			begin_shop_mode("Orrin Bazaar","This bazaar stocks some of the best equipment and goods in the valley. As if that wasn't enough, there's a great sandwich shop there too.", 7, 2, 5);
			}
		}
break;

beginstate 21; //Encounter drakes in preserve (part of Orrin quest)
	reset_dialog();
	message_dialog("As you enter this mossy stone circle, the two drakes you spotted earlier suddenly burst out of the treetops, streaking towards you. However, one of the pair veers off and heads out of the Preserve.","The only problem is, that still leaves you with one drake.");
	set_out_fight_town_loaded(6);
break;

beginstate 22; //End Encounter for Orrin quest
	reset_dialog();
	message_dialog("The drake lies dead. Your best guess is that it was sent by the Order of Flame, but you can't think of a way to be sure of it.","Either way, the residents of Orrin will definitely love to hear about this.");
break;

beginstate 23; //Start drake encounter for Orrin quest
	if (get_flag(201,8) != 1) {
		create_out_spec_enc(0);
		set_flag(201,8,1);
		}
break;

beginstate 24; //Fled from Orrin drake quest
	reset_dialog();
	message_dialog("You try to escape the drake, but it only charges you again!","");
	create_out_spec_enc(0);
break;

//STATES 30-39: Slomar

beginstate 30; //Enter Slomar, get attacked by lizards
//if you haven't fought 'em yet
	if (get_flag(201,9) != 1) {
		message_dialog("You approach the town of Slomar, strolling through an impressive wall of hedges, and your attention is immediately caught by a scuffle between a group of townsfolk and a swarm of lizards.","This must be the work of the Order of Flame, because quite a few of the lizards are breathing fire. The people seem close to defeat, so you charge in, hoping to make a difference.");
		create_out_spec_enc(1);
		set_flag(201,9,1);
		}
break;
		
beginstate 31; //Beaten lizards
	message_dialog("A few villagers walk up to you, praising your efforts while tending to their wounded. A merchant approaches you, offering you a small pouch of coins for your help.", "_I know this may not be much, but please accept this token of our gratitude._");
	award_party_xp(500,20);
	change_coins(250);
	message_dialog("The merchant continues, _We wish you the best of luck in your quest to find Ephesos. The entire valley prays for your success._","You thank him, realizing that the Order of Flame may be more powerful than you thought.");
	inc_flag(100,2,1); //Chalk up another quest point for Oakleaf
break;

beginstate 34; //Slomar Farmers' Market
	if(get_flag(201,10) != 1) {
		message_dialog("You enter the village of Slomar, and are immediately greeted by grateful villagers, who profusely thank you for your help with the lizards.","However, you can't help but notice that they still seem a little depressed. The disappearance of Ephesos has apparently hit this village hard also.");
		reset_dialog();
		add_dialog_str(0, "Passing through the village, you find yourself awed at how fertile the entire area is. Looking over the farmers' crops, you can't help but wonder at the good that the druids must've done for these people.", 0);
		add_dialog_str(1, "Noticing that you've been looking at their crops, a few farmers approach you, asking if you'd like to buy some.", 0);
		set_flag(201,10,1);
	}
	else {
		reset_dialog();
		add_dialog_str(0, "As you approach the village square, the farmers of Slomar come greet you again. As before, their produce and herbs look fresh and tempting.",0);
	}
	add_dialog_choice(0, "Leave");
	add_dialog_choice(1, "Shop");
	choice = run_dialog(1);
	if(choice == 2) {
		begin_shop_mode("Slomar Farmers' Market","Slomar grows some of the best-looking produce you've ever seen. And it's cheap, too.",8,1,-1);
	}
break;

//STATES 50-59 - Oakleaf's encounters, pre and post departure.

beginstate 50; //set up enc. w/ oakleaf
	if((get_flag(201,16) != 1) && (get_flag(1,10) == 1)) {
		reset_dialog();
		message_dialog("As you wander back to the south end of the valley, you notice a robed figure walking to the southeast of you. It appears to be Brother Oakleaf! He waves you over, hoping to get moving quickly.","");
		set_flag(201,16,1);
		}
break;

beginstate 51; //actual encounter
if(get_flag(201,16) == 1) {
	if(has_item(448) == 1) {
		reset_dialog();
		add_dialog_str(0, "You meet Brother Oakleaf at what looks like a sheer cliff face, one which towers at least two hundred feet above you.",0);
		add_dialog_str(1, "Brother Oakleaf asks to see the artifacts from the Temple, and once you show them to him, he motions toward the cliff. A small crack appears in the rock face.",0);
		add_dialog_str(2, "It's not much, but it's enough for you and Brother Oakleaf to fit through. He leads you through to a very narrow canyon, one which probably can't even be seen from above.",0);
		run_dialog(1);
		out_move_party(37,35);
		set_flag(100,1,1);
		}
	else {
		reset_dialog();
		message_dialog("Brother Oakleaf quickly greets you, and asks if you retrieved the artifacts from the Temple. When you tell him you haven't, Oakleaf gets a bit angry.","_Go back and get those artifacts, or we can't leave the valley!_ he says, turning you away.");
		}
	}
break;

beginstate 52; //Before cliffs (skyshard reminder)
	if (get_flag(201,17) != 1) {
		reset_dialog();
		add_dialog_str(0, "Brother Oakleaf stops you for a minute, and points out the light blue orb you retrieved from the Temple.", 0);
		add_dialog_str(1, "_If you didn't realize this yet, this is the Skyshard, one of our Order's most prized artifacts. It bestows the power of flight, much like the legendary Orb of Thralni._", 0);
		add_dialog_str(2, "_Ephesos and I worked for months to create this. Now, we can finally put it to good use. Ahead are some cliffs, as you can see. We need to climb them._", 0);
		add_dialog_str(3, "_When we reach the foot of the cliffs, use the Skyshard, and fly up and to the north. When we reach the top, you'll see the mouth of a cave._", 0);
		add_dialog_str(4, "_At the cave, wait for the power of flight to wear off. Then, we can go about leaving the valley to find Ephesos._",0);
		run_dialog(1);
		set_flag(201,17,1);
		}
break;

beginstate 53; //Final message at cave opening, leave valley.
	if((get_flag(201,18) != 1) && (party_has_status(25) == 0)) {
		reset_dialog();
		message_dialog("You reach the top of the cliffs, where a wide cave mouth stands in front of you. Brother Oakleaf steps toward the cave. _This is our path to find Ephesos. Follow me in._", "");
		set_flag(201,18,1);
		}
	else if((get_flag(201,18) != 1) && (party_has_status(25) != 0)) {
		block_entry(1);
		reset_dialog();
		message_dialog("_We cannot enter the cave until the Orb's power wears off. Let us return to the ground._ Brother Oakleaf says.","");
		}

break;

//STATES 90-99 - Misc.

beginstate 90; //Sharp pointy rocks at bottom of chasm
	block_entry(1);
	reset_dialog();
	if (get_flag(201,15) != 1) {
		message_dialog("Now that you take a good look at this canyon, you realize that the floor of it is almost completely covered in pointy rocks. If you were to fall, you'd die instantly.","Needless to say, flying over is too big of a risk.");
		set_flag(201,15,1);
	}
break;

beginstate 95; //blind sage - (quick strike)
	outdoor_enc_result(3); //won't reappear
	reset_dialog();
	add_dialog_str(0, "As you walk through this tranquil glade, you notice a druid sitting by the river. He faces away from you, and he doesn't seem to notice your presence at all, and continues silently gazing at the waterfall to the northwest.",0);
	add_dialog_str(1, "You approach him quietly, waiting for him to notice you. He doesn't. Then, once you're about ten feet from him, he spins around and draws a staff from out of his cloak.", 0);
	add_dialog_str(2, "_Who disturbs me?_ he yells, to nobody in particular. _What unkind soul would trouble a blind man?_", 0);
	add_dialog_str(3, "This changes things a bit. To put him at ease, you calmly tell him that you're helping the Order. He immediately brightens up.", 0);
	run_dialog(1);
	reset_dialog();
	add_dialog_str(0, "_Well, since I know you're not enemies, I don't have to kill you._ he says. As if to demonstrate, he leaps forward at you with blinding speed and brings his staff to within inches of cracking your skull. You don't even have time to react.",0);
	add_dialog_str(1, "_And now that I have your attention,_ he continues, _I can help you._", 0);
	add_dialog_str(2, "Once you recover from your disbelief, the druid spends the better part of an hour teaching you tricks to move more quickly in combat. You come away from the lesson feeling much faster.", 0);
	add_dialog_str(3, "Before you can turn around and thank the man, he has disappeared into the woods. You're suddenly very glad that he's on your side.",0);
	run_dialog(1);
	alter_stat(1000,19,1);
	set_flag(201,11,1);
break;